# 实现存取款
import random

balance = 500000
username = "周杰伦"


def menu():
    while True:
        print("-----------------主菜单------------------")
        print(f"{username},您好，欢迎来到黑马银行ATM，请选择操作")
        print("查询余额  [输入1]")
        print("存款     [输入2]")
        print("取款     [输入3]")
        print("退出     [输入4]")

        choose = input("请输入您的选择：")
        if not choose.isdigit():
            print("请输入正确的数字")

        t = int(choose)
        if t == 4:
            break
        else:
            choose_type(t)

        next_operator = input("继续操作还是退出[Y/N]：")

        if next_operator == "N":
            break


def choose_type(t: int):
    if t == 1:
        query_balance()
    else:
        modify_balance(t, random.randint(10000, 50000))


def query_balance():
    print("===================================")
    print(f"{username},您的余额剩余：{balance}")
    print("===================================")


def modify_balance(t: int, money: int):
    global balance
    if t == 2:
        balance = balance + money
        print("===================================")
        print(f"{username}，您存款{money}成功，余额剩余{balance}")
        print("===================================")
    else:
        balance = balance - money
        print("===================================")
        print(f"{username}，您取款{money}成功，余额剩余{balance}")
        print("===================================")


# 调用实现
menu()
